<?php

class ManufacturerModel extends Models
{
    public $id, $name;

    protected $tableName='manufacturer';

    public function getVendors($products)
    {
        if(!$products) return false;

        $result=array();
        $vendorsNames=array();
        $firstProduct=array_shift($products);
        $vendor=$firstProduct->VendorName;

        foreach($products as $product){
            if($vendor && $product->VendorName!=$vendor) $vendorsNames[]=$product->VendorName;
        }

        if($vendorsNames){
            $vendorsNames[]=$firstProduct->VendorName;
            foreach($vendorsNames as $vendorName){
                $vendorModel=new self(null);
                if($vendor=$this->findByAttributes(array('name'=>$vendorName))){
                    $vendorModel->id=$vendor['manufacturer_id'];
                    $vendorModel->name=$vendorName;
                    $result[]=$vendorModel;
                }
            }
        }

        return $result;
    }

    public function getBrandsNames()
    {
        $result=array();
        if($brands=$this->findAll()){
            foreach($brands as $brand){
                if($brand['name']) $result[]=strtolower($brand['name']);
            }
        }
        return $result;
    }

    public function getTableName(){
        return $this->tableName;
    }
}